package com.neuedu.controller;

import java.io.IOException;
import java.sql.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.neuedu.projos.Product;
import com.neuedu.service.ProServ;
import com.neuedu.service.ProServImpl;

/**
 * Servlet implementation class UpdateServ3
 */
@WebServlet("/UpdateServ3")
public class UpdateServ3 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateServ3() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		String proId =request.getParameter("proID");
		String proname =request.getParameter("proName");
		String proPrice =request.getParameter("proPrice");
		String proCount =request.getParameter("proCount");
		String proMannufacturer =request.getParameter("proMannufacturer");
		String proDate =request.getParameter("proDate");
		String proImg =request.getParameter("proImg");
		String proDes =request.getParameter("proDes");
		String proPlace =request.getParameter("proPlace");
		String cId =request.getParameter("cId");
		Integer prID=Integer.valueOf(proId.trim());
		Double prPrice =Double.valueOf(proPrice);
		Integer pCount =Integer.valueOf(proCount);
		Date date =Date.valueOf(proDate);
		Integer cateId =Integer.parseInt(cId);
		ProServ ps = new ProServImpl();
		Product p = new Product(prID, null, proname, prPrice, pCount, proMannufacturer, date, proImg, proDes, proPlace, cateId);
		boolean updateProduct =ps.updateProduct(p);
		if(updateProduct==true)
		{
			response.sendRedirect("ShowProListServ2?pageNum=1");
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
